package com.dbappsecurity.jsbridge;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import com.dbappsecurity.jsbridge.webview.CompletionHandler;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;

public class JsDialogUtils {
  public static AlertDialog getMenu(Context context, String title, List<String> list,
      CompletionHandler handler) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(title + "");
    // builder.setMessage("是否确认退出?"); //设置内容
    //    builder.setIcon(R.mipmap.ic_launcher);
    // 设置列表显示，注意设置了列表显示就不要设置builder.setMessage()了，否则列表不起作用。
    builder.setItems(list.toArray(new CharSequence[list.size()]), new DialogInterface.OnClickListener() {
      @Override public void onClick(DialogInterface dialog, int which) {
        dialog.dismiss();

        Map<String, String> map = new HashMap<>();
        map.put("index", "" + which);
        JSONObject jsonObject = new JSONObject(map);
        handler.setProgressData(jsonObject.toString());
      }
    });
    return builder.create();
  }
}
